use std::io;
use rand::Rng;
use std::cmp::Ordering;

fn main() {
    println!("Guess the number!");

    let mut a = 1;
    let mut b = 101;
    let secret_number = rand::thread_rng().gen_range(a, b);

    loop {
        println!("Please input your guess.");

        let mut guess = String::new();

        io::stdin().read_line(&mut guess).expect("Failed to read line");

        let guess: u32 = guess.trim().parse().expect("Please type a numer!");

        println!("You guessed:{}", guess);

        match guess.cmp(&secret_number) {
            Ordering::Less => {
                a = guess;
                println!("太小了 [{},{}]", a, b);
            },
            Ordering::Greater => {
                b = guess;
                println!("太大了 [{},{}]", a, b);
            },
            Ordering::Equal => {
                println!("中了");
                break;
            },
        }
    }
}